package com.yingsheng.bi.hks.config;

import com.yingsheng.bi.hks.config.props.OssProperties;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.*;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;


@Configuration
public class OssConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "oss")
    public OssProperties ossProperties() {
        return new OssProperties();
    }

    @Bean
    public MinioClient minioClient(OssProperties ossProperties) {
        return new MinioClient.Builder().credentials(ossProperties.getAccessKey(), ossProperties.getSecretKey())
                .endpoint(ossProperties.getEndpoint()).build();
    }

    public static void main(String[] args) throws Exception {

//        OssConfiguration configuration = new OssConfiguration();
//        OssProperties properties = new OssProperties();
//        properties.setAccessKey("minioadmin");
//        properties.setSecretKey("minioadmin");
//        properties.setEndpoint("http://124.220.3.30:9000");
//        MinioClient client = configuration.minioClient(properties);
//
//        Map<String, String> headers = new HashMap<>();
//        headers.put("Content-Type", "image/png");
//        headers.put("Cache-Control", "no-cache");
//
//
//
//        InputStream in = Files.newInputStream(Paths.get("D:\\yuerguanjia_t.png"));
//        client.putObject(PutObjectArgs.builder()
//                .bucket("miniapp-xjy-dev")
//                .object("/public/fuwu/yuerguanjia_t.png")
//                .stream(in, in.available(), -1)
//                .extraHeaders(headers)
//                .build());
        Path path = Paths.get("D:\\Admin_59\\Desktop\\黄-工作空间\\a.pdf");
        String contentType = Files.probeContentType(path);
        System.out.println(contentType);

    }

}
